package com.example.loginplaus;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    private EditText ed_user;
    private EditText ed_pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ed_pwd = findViewById(R.id.main_ed_pwd);
        ed_user = findViewById(R.id.main_ed_user);
    }

    public void Login(View view) {
        Intent intent = getIntent();
        String myUser = ed_user.getText().toString();
        String myPwd = ed_pwd.getText().toString();
        if (intent.getStringExtra("name") != null) {
            String name = intent.getStringExtra("name");
            String age = intent.getStringExtra("age");
            String user = intent.getStringExtra("user");
            String pwd = intent.getStringExtra("pwd");
            if (myUser.equals(user) && myPwd.equals(pwd)) {
                Intent intent1 = new Intent(this,User.class);
                intent1.putExtra("name",name);
                intent1.putExtra("age",age);
                intent1.putExtra("user",user);
                intent1.putExtra("pwd",pwd);
                startActivity(intent1);
            }else {
                Toast.makeText(this,"账号或密码错误！",Toast.LENGTH_LONG).show();
            }
        }else {
            if (myUser.equals("admin") && myPwd.equals("123456")) {
                startActivity(new Intent(this,User.class));
            }else {
                Toast.makeText(this,"账号或密码错误！",Toast.LENGTH_LONG).show();
            }
        }
    }

    public void Register(View view) {
        startActivity(new Intent(this,Register.class));
    }
}